﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Giaiphongmatbang.DataModel;
using Giaiphongmatbang.BLL;
using Giaiphongmatbang.Utility;

namespace Giaiphongmatbang
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            txtUserName.Focus();
            if (!IsPostBack)
            {
            }
        }

        protected void btnLogin_Click(object sender, ImageClickEventArgs e)
        {
            string UserName = txtUserName.Text;
            string Password = txtPassword.Text;
            User user = new UserRepository().GetByUserNameAndPassWord(UserName,Encryptions.EncryptUTF8MD5(Password));
            if (user == null)
            {
                ltrError.Text = "Sai tên đăng nhập hoặc mật khẩu!";
            }
            else
            {
                Session["User"] = user;
                Response.Redirect((string)Session["returnURL"] ?? "duan.aspx");
            }
        }

        protected void btnCancel_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("duan.aspx");
        }


    }
}